<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<load href="__PUBLIC__/common.css"/>
	<load href="__PUBLIC__/Admin/resources/scripts/jquery-1.7.2.min.js"/>
	<load href="__PUBLIC__/Boot/bootstrap.min.css"/>
	<load href="__PUBLIC__/Boot/bootstrap.min.js"/>
	<load href="__PUBLIC__/Button/css/font-awesome.min.css"/>
</head>
<body>
	<div>
		<p>
 		 <button type="button" class="btn btn-primary ">栏目列表</button>
 		 <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">添加顶级栏目</button>
 		 <button type="button" id="element" onclick="cache(this)" class="btn btn-info">更新缓存</button>
 		 <span class="Upcache"  style="width:80px;height:20px;display: inline-block; color:blue; display: none;">缓存成功</span>
		</p>
	</div>
	<!-- 模型缓存 -->
	<script type="text/javascript">
	function cache(obj){
		$.get("{:U('Category/updateCache')}",function(data){
			if(data==1){
				$(".Upcache").fadeIn('2000').fadeOut('1000');
			}else{
				$(".Upcache").html("缓存失败");
				$(".Upcache").fadeIn('1000').fadeOut('1000');
			}
		})
	}
	</script>

	<div class="table-responsive">
  		<table class="table table-striped">
    		<tr>
				<td class="w100">cid</td>
				<td>栏目名称</td>
				<td>模型</td>
				<td class="w200">操作</td>
			</tr>
			<volist name="cate" id="c">
			<tr>
				<td class="w100">{$c.cid}</td>
				<td ><span style='list-style:none;padding-left:{$c.level}6px;'> |--</span>{$c.cname}</td>
				<td>
					<volist name="data" id="n">
						<if condition="$n['mid'] eq $c['mid']">
			 			{$n.m_name}
			 		   </if>
		 			</volist>	
					
				</td>
				<td class="w300">
					<!-- {:U('category/addcate',array('cid'=>$c['cid']))} -->
					<a href="javascript:;" attr="{$c.cid}" onclick="return addcate(this)" class="btn btn-default icon-cog" data-toggle="modal" data-target="#mycate">添加子栏目</a>
					<a href="javascript:;"  attr="{$c.cid}" onclick="return edit(this)" class="btn btn-default  icon-edit" data-toggle="modal" data-target="#edit">修改</a>
					<a href="javascript:;"  attr="{$c.cid}" onclick="return del(this)" class="btn btn-default  icon-cut">删除</a>
				</td>
			</tr>
			</volist>
  		</table>
	</div>

<!-- 删除 -->
<script type="text/javascript">
	function del(obj){
		if(confirm('确认要删除吗？')){
			var cid = $(obj).attr('attr');
			$.post("{:U('del')}",{cid:cid},function(data){
				if(data==1){
					$(obj).parent('td').parent('tr').remove();
				}
			})
		}
		return false;
	}
	function fun(obj){
		alert($(obj).val());
	}
</script>
<!-- 添加顶级栏目弹窗 -->
<form action="{:U('Category/add')}"  method="post">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">添加顶级栏目</h4>
      		</div>
     		 <div class="modal-body">
     		 	
       			 <table class="table">
       			 	<tr class="success">
       			 		<td>选择模型：</td>
       			 		<td>
       			 			<select name="mid"  class="form-control">
       			 				<volist name="data" id="m">
					 			<option value="{$m.mid}" selected="">{$m.m_name}</option>
					 			</volist>
							</select>
       			 		</td>
       			 	</tr>
       			 	<tr class="warning">
       			 		<td>跳转地址：</td>
       			 		<td>
       			 			<input type="text" name="url" class="form-control" placeholder="url地址">
       			 		</td>
       			 	</tr>
					<tr class="success">
						<td>栏目名称：</td>
						<td>
							<input type="text" name="cname" class="form-control" placeholder="栏目名称">
						</td>
					</tr>
					<tr class="warning">
						<td>栏目关键字：</td>
						<td>
							<input type="text" name="c_keywords" class="form-control" placeholder="关键字">
						</td>
					</tr>
					<tr class="success">
						<td>栏目描述：</td>
						<td>
							<textarea name="c_description" class="form-control" rows="3"></textarea>
						</td>
					</tr>
					<tr class="success">
						<td>栏目类型：</td>
						<td style="color:#555; font-weight: 400; font-size:12px; ">
							<label ><input type="radio" checked='' name='tpl_style' value='1'>普通栏目</label>
							<label ><input type="radio" name='tpl_style' value='2'>频道封面</label>
							<label ><input type="radio" name='tpl_style' value='3'>外部链接</label>
							<label ><input type="radio" name='tpl_style' value='4'>单页面</label>
						</td>
					</tr>
					<tr class="warning">
						<td>选择封面模板：</td>
						<td>
							<select name="index_tpl" multiple class="form-control">
       			 				<volist name="tpl" id="t">
					 			<option value="{$t}" >{$t}</option>
					 			</volist>
							</select>
						</td>
					</tr>
					<tr class="success">
						<td>选择列表页模板：</td>
						<td>
							<select name="list_tpl" multiple class="form-control">
       			 				<volist name="tpl" id="t">
					 			<option value="{$t}" >{$t}</option>
					 			</volist>
							</select>
						</td>
					</tr>
					<tr class="warning">
						<td>选择文章页模板：</td>
						<td>
							<select name="acr_tpl" multiple class="form-control">
       			 				<volist name="tpl" id="t">
					 			<option value="{$t}" >{$t}</option>
					 			</volist>
							</select>
						</td>
					</tr>
					
       			 </table>

     		 </div>
      		<div class="modal-footer">
        <button type="submit" class="btn btn-primary">提交</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</form>
<script type="text/javascript">
	function addcate(obj){
		var cid=$(obj).attr('attr');
		$('select[name="pid"] option').each(function(){
			if($(this).val()==cid){
				$(this).attr('selected','');
			}
		})
	}
</script>
<!-- 添加子栏目弹出 -->
<form action="{:U('Category/add')}"  method="post">
<div class="modal fade" id="mycate" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">添加子栏目</h4>
      		</div>
     		 <div class="modal-body">
     		 	<!-- <input id="pid" type="text" name='pid' vlaue='' > -->
       			 <table class="table">
       			 	<tr class="success">
       			 		<td>选择模型：</td>
       			 		<td>
       			 			<select name="mid" class="form-control">
       			 				<volist name="data" id="m">
					 			<option value="{$m.mid}" selected="">{$m.m_name}</option>
					 			</volist>
							</select>
       			 		</td>
       			 	</tr>
       			 	<tr class="warning">
						<td>上级栏目：</td>
						<td>
							<select name="pid" class="form-control">
       			 				<volist name="cate" id="c">
       			 				<if condition="$c['pid']==0 ">
					 			<option value="{$c.cid}" selected="">{$c.cname}</option>
					 			</if>
					 			</volist>
							</select>
						</td>
					</tr>
					<tr class="success">
						<td>栏目名称：</td>
						<td>
							<input type="text" name="cname" class="form-control" placeholder="栏目名称">
						</td>
					</tr>
					<tr class="warning">
						<td>栏目关键字：</td>
						<td>
							<input type="text" name="c_keywords" class="form-control" placeholder="关键字">
						</td>
					</tr>
					<tr class="success">
						<td>栏目描述：</td>
						<td>
							<textarea name="c_description" class="form-control" rows="3"></textarea>
						</td>
					</tr>
					<tr class="success">
						<td>栏目类型：</td>
						<td style="color:#555; font-weight: 400; font-size:12px; ">
							<label ><input type="radio" checked='' name='tpl_style' value='1'>普通栏目</label>
							<label ><input type="radio" name='tpl_style' value='2'>频道封面</label>
							<label ><input type="radio" name='tpl_style' value='3'>外部链接</label>
							<label ><input type="radio" name='tpl_style' value='4'>单页面</label>
						</td>
					</tr>
					<tr class="warning">
						<td>选择封面模板：</td>
						<td>
							<select name="index_tpl" multiple class="form-control">
       			 				<volist name="tpl" id="t">
					 			<option value="{$t}">{$t}</option>
					 			</volist>
							</select>
						</td>
					</tr>
					<tr class="success">
						<td>选择列表页模板：</td>
						<td>
							<select name="list_tpl" multiple class="form-control">
       			 				<volist name="tpl" id="t">
					 			<option value="{$t}" >{$t}</option>
					 			</volist>
							</select>
						</td>
					</tr>
					<tr class="warning">
						<td>选择文章页模板：</td>
						<td>
							<select name="acr_tpl" multiple class="form-control">
       			 				<volist name="tpl" id="t">
					 			<option value="{$t}" >{$t}</option>
					 			</volist>
							</select>
						</td>
					</tr>
					
       			 </table>

     		 </div>
      		<div class="modal-footer">
        <button type="submit" class="btn btn-primary">提交</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</form>
<!-- 编辑模型弹窗 -->
<script type="text/javascript">
	function edit(obj){
		var cid=$(obj).attr('attr');
		// alert(cid);
		$.post("{:U('edit')}",{cid:cid},function(data){
			$('#editCategory').html(data);
			// alert(data);
		})
		
	}
</script>


<form action="{:U('Category/edit')}" method="post">
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">修改栏目</h4>
      		</div>
     		 <div id="editCategory" class="modal-body">
     		 	
       			 

     		 </div>
      		<div class="modal-footer">
        <button type="submit" class="btn btn-primary">提交</button>
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div>
</form>

</body>
</html>
